/*
 * @Author: Leo.wang wanglizhigs@163.com
 * @Date: 2023-11-14 17:15:35
 * @LastEditors: Leo.wang wanglizhigs@163.com
 * @LastEditTime: 2023-11-23 11:16:27
 * @FilePath: /three-react/src/pages/Camera/Camera1.tsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { useEffect, useRef } from "react"
import createRender from '@/createRender';
import * as THREE from 'three'

const state = {}
export default function Page() {

  const container = useRef(null);
  useEffect(() => {
    if (!state.isMounted) {
      createRender(container)(render);
      state.isMounted = true;
    }
  }, [])

  function render(scene, camera, renderer) {
    const geometry1 = new THREE.BoxGeometry(50,50,50)
    const material1 = new THREE.MeshLambertMaterial({
      color: 0x00ffff
    })
    const geometry2 = new THREE.BoxGeometry(50,50,50)
    const material2 = new THREE.MeshLambertMaterial({
      color: 0x00ffff
    })
    const geometry3 = new THREE.BoxGeometry(50,50,50)
    const material3 = new THREE.MeshLambertMaterial({
      color: 0x00ffff
    })
    const mesh1 = new THREE.Mesh(geometry1, material1)
    const mesh2 = new THREE.Mesh(geometry2, material2)
    const mesh3 = new THREE.Mesh(geometry3, material3)
    mesh2.position.set(100, 0, 0);
    mesh3.position.set(0, 100, 0);
    scene.add(mesh1);
    scene.add(mesh2);
    scene.add(mesh3);


    const raycaster = new THREE.Raycaster();
    raycaster.ray.origin = new THREE.Vector3(-100, 0, 0);
    raycaster.ray.direction = new THREE.Vector3(1, 0, 0);

    const  inserset = raycaster.intersectObjects([mesh1,mesh2, mesh3])
    console.log('inserset', inserset)

    inserset[0].object.material.color.set(0xff0000)
    
  }

  return (
    <div id="container" className="full container" ref={container}></div>
  )
}